// 实现用户管理子服务的服务器
#include "gateway_server.hpp"

DEFINE_bool(run_mode, false, "程序的运行模式，false-调试； true-发布；");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

// 命令行解析获取服务注册中心地址
DEFINE_string(registry_host, "http://127.0.0.1:2379", "服务注册中心地址");
DEFINE_string(base_service, "/service", "服务监控根目录");

// 关心的服务名称
DEFINE_string(care_file_service, "/service/file_service", "文件子服务");
DEFINE_string(care_user_service, "/service/user_service", "用户子服务");
DEFINE_string(care_speech_service, "/service/speech_service", "语音转文字子服务");
DEFINE_string(care_transmit_service, "/service/transmit_service", "消息转发子服务");
DEFINE_string(care_message_service, "/service/message_service", "消息存储子服务");
DEFINE_string(care_friend_service, "/service/friend_service", "好友管理子服务");

DEFINE_int32(http_listen_port, 9000, "http服务器监听端口");
DEFINE_int32(websock_port, 9001, "websock服务器监听端口");

// redis的参数
DEFINE_string(redis_host, "127.0.0.1", "这是服务器的监听地址，格式为[0.0.0.0]");
DEFINE_int32(redis_port, 6379, "这是redis服务器的监听端口，格式为[6379]");
DEFINE_bool(redis_keep_alive, true, "是否启用长连接保活，格式为[true/false]");
DEFINE_int32(redis_db_flag, 0, "库的编号，默认为0");

int main(int argc, char *argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    bite_im::initLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    bite_im::GatewayServerBuilder gsb;

    // 获取redis客户端
    gsb.make_redis_object(FLAGS_redis_host, FLAGS_redis_port, FLAGS_redis_keep_alive, FLAGS_redis_db_flag);
    // 获取查找模块
    gsb.make_find_object(FLAGS_registry_host, FLAGS_base_service, FLAGS_care_file_service, FLAGS_care_user_service,
                         FLAGS_care_speech_service, FLAGS_care_transmit_service, FLAGS_care_message_service, FLAGS_care_friend_service);
    // 获取端口
    gsb.get_gateway_port(FLAGS_websock_port, FLAGS_http_listen_port);
    auto server = gsb.build();
    server->start();
    return 0;
}